<template>
  <el-container class="login">
    <el-header>
      <h2 style="text-align: center">墨盘</h2>
    </el-header>
    <el-main>
      <div style="height: 400px; width: 400px; margin: auto auto">
        <el-form
            label-position="top"
            style="margin-top: 5em"
            :rules="loginRules"
            :model="formState"
        >
          <el-form-item
              label="邮箱"
              prop="email"
          >
            <el-input
                v-model.trim="formState.username"
                placeholder="请输入用户名/邮箱"
            ></el-input>
          </el-form-item>
          <el-form-item
              label="密码"
              prop="password"
          >
            <el-input
                v-model.trim="formState.passwd"
                type="password"
                placeholder="请输入密码，六位数以上"
                @keyup.enter="goLogin"
            >
            </el-input>
          </el-form-item>
          <el-form-item>

            <div style="display: flex; justify-content: center">
              <el-button
                  @click="goLogin"
                  type="success"
                  @keyup.enter.native="goLogin"
                  :loading="submiting"
              >登录</el-button>
            </div>
            <div style="display: flex; justify-content: flex-end">
              <p>还没注册？<el-link
                  style="color:white"
                  type="success"
                  @click="goRegister"
                  href="javascript:;"
              >点击这里 </el-link>
              </p>
            </div>

          </el-form-item>
        </el-form>
      </div>
    </el-main>
  </el-container>
</template>

<script>

import {mapState,mapMutations} from 'vuex';
export default {
  name: "Login",
  data() {
    return {
      formState:{},
      loginRules:{},
      submiting:false,
    };
  },
  methods: {
    goLogin() {
      var that = this;
      that.submiting = true;
      that.$axios.post('login/login',that.formState).then(res=>{
        that.submiting = false;
        if(res.data.code == 1){
          that.$store.commit('login',res.data.data);
          that.$router.push('/');
        }
      }).catch(res=>{
        that.submiting = false;
        that.$message.error('登陆失败');
      })
    },
    goRegister(){
      this.$router.push({name:'Register'});
    }
  }
}
</script>

<style >
.login {
  margin: 0;
  width: 100%;
  height: 100vh;
  color: #fff;
  /*背景颜色设置渐变*/
  background: linear-gradient(to right, #ee7752, #e73c7e, #23a6d5, #23d5ab);
  background-size: 400% 400%;
  animation: gradientBG 15s ease infinite;

}
.login  .el-header,
.el-footer {
  margin: 0;
  padding: 0;
  height: 35px;
  color: white;
}
.login .el-main {
  margin: 0;
  padding: 0;
  height: calc(100vh - 120px);
  /* background-image: url('@/assets/莫哈韦沙漠晚上.jpg'); */
}
.login p,
.el-form-item__label {
  color: white;
}
@keyframes gradientBG {
  0% {
    background-position: 50% 50%;
  }
  50% {
    background-position: 100% 100%;
  }
  100% {
    background-position: 50% 50%;
  }
}

.el-loading-spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  -webkit-animation: typing 2s linear infinite alternate;
  -moz-animation: typing 1s linear infinite alternate;
  animation: typing 2s linear infinite alternate;
  margin: 10px auto;
  position: relative;
  left: 50px;
}
@keyframes typing {
  75% {
    background-color: rgb(2, 243, 130);
    box-shadow: 40px 0px 0px 0px rgb(2, 243, 130),
    80px 0px 0px 0px rgb(2, 243, 130);
  }
}
.el-loading-spinner .circular {
  display: none;
}
</style>